<template>
  <div class="login-container">
    <div class="logo" />
    <div class="form">
      <div class="bt">智慧园区-登录</div>
      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="loginForm" :model="loginForm" :rules="loginRules">
          <el-form-item prop="username">
            <div class="zh">账号</div>
            <el-input v-model="loginForm.username" />
          </el-form-item>
          <el-form-item prop="password">
            <div class="zh">密码</div>
            <el-input v-model="loginForm.password" show-password />
          </el-form-item>
          <el-form-item prop="modelUuid">
            <div class="zh">模型uuid:</div>
            <el-input v-model="loginForm.modelUuid" show-password />
          </el-form-item>
          <el-form-item prop="remember">
            <el-checkbox v-model="loginForm.remember">
              记住我
            </el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button style="width:230px;height:25px;font-size: 12px;line-height: 2px;" type="primary" @click="login">登 录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        username: 'demo',
        password: 'Hmzs%001',
        modelUuid: '66ea8d2a-7416-4be5-ba7e-c030cf88b3f3',
        remember: false
      },
      loginRules: {
        username: [{ required: true, message: '请输入账号', trigger: 'blur' },
          { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
        ],
        modelUuid: [{ required: true, message: '请输入模型uuid', trigger: 'blur' },
          { min: 6, max: 50, message: '长度在 6 到 50 个字符', trigger: 'blur' }
        ],
        remember: [{ validator: (rule, value, callback) => {
          if (value) {
            callback()
          } else {
            callback(new Error('请勾选'))
          }
        }, trigger: 'change'
        }]
      }
    }
  },
  methods: {
    async login() {
      try {
        await this.$refs.loginForm.validate() // await总是会等待后面的promise进行resolve
        await this.$store.dispatch('user/login', { username: this.loginForm.username, password: this.loginForm.password })
        // 跳转到主页
        this.$router.push('/')
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>
<style lang="scss">
.login-container {
  display: flex;
  align-items: stretch;
  height: 100vh;
  .logo {
    flex: 3;
    background: rgba(38, 72, 176) url(../../assets/common/login-bg-e4ea539c.svg)
      no-repeat center / cover;
    border-top-right-radius: 60px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    padding: 0 100px;
    .icon {
      background: url(../../assets/common/logo.png) no-repeat 70px center /
        contain;
      width: 300px;
      height: 50px;
      margin-bottom: 50px;
    }
    p {
      color: #fff;
      font-size: 18px;
      margin-top: 20px;
      width: 300px;
      text-align: center;
    }
  }
  .form {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-top: 150px;
    padding-left: 70px;
    padding-right: 70px;
    .el-card {
      border: none;
      padding: 0;
    }
    .bt {
      margin-bottom:20px ;
      padding-left: 20px;
      font-size: 22px;
      font-weight: 500;
      color: #1e2023;
    }
    .zh {
      padding: 0;
      margin-bottom:-10px ;
      font-size: 14px;
      color: #8b929d;
    }
    .el-input {
      width: 230px;
      height: 10px;
      // .el-input__inner {
      //   background: #f4f5fb;
      // }
    }
    .el-input__inner {
     height: 25px;
      border-radius: 5px;
      border-color: rgb(36, 36, 36);
    }
    .el-checkbox {
      color:#606266;
    }
  }
}
</style>
